/**
 * 
 */
package com.rf.richfitwheel.admin.utils;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * json工具类
 * @author hushouquan
 *
 */
public class JacksonJsonUtil {
	/*
	 * 001.json转换成对象
	 * @param:传入对象，json字符串
	 * @return:Object
	 */
	public static Object jsonToObj(Object obj,String jsonStr) throws JsonParseException, JsonMappingException, IOException {
		ObjectMapper mapper = new ObjectMapper();	
	    return obj = mapper.readValue(jsonStr, obj.getClass());
	}
	/*
	 * 002.对象转换成json
	 * @param:传入对象
	 * @return:json字符串
	 */
	public static String objToJson(Object obj) throws JsonProcessingException {
		ObjectMapper mapper = new ObjectMapper();
		return mapper.writeValueAsString(obj);
	}

}
